import { post } from '@/core/request/post'
import { Loading } from 'element-ui'

export function load (url, data = {}) {
  var loadingInstance = Loading.service({
    lock: true,
    text: 'Loading',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  })

  setTimeout(() => {
    if (loadingInstance) {
      loadingInstance.close()
      loadingInstance = 0
    }
  }, 20000)

  return new Promise((resolve, reject) => {
    post(url, data).then(
      response => {
        if (loadingInstance) {
          loadingInstance.close()
          loadingInstance = 0
        }
        resolve(response)
      },
      error => {
        if (loadingInstance) {
          loadingInstance.close()
          loadingInstance = 0
        }
        reject(error)
      }
    )
  })
}
